//
//  HMHomeCell.m
//  LoveFreshBeen
//
//  Created by huodian on 16/10/15.
//  Copyright © 2016年 魏根. All rights reserved.
//

#import "HMHomeCell.h"

#import "HomeFocusModel.h"

#import "HMHomeBtn.h"

#import <Masonry.h>

#import <UIButton+WebCache.h>

@interface HMHomeCell()



@property(nonatomic,strong)NSMutableArray* btnArray;

@property(nonatomic,strong)NSArray* array;


@end

@implementation HMHomeCell



-(NSMutableArray *)btnArray
{
    if (_btnArray == nil)
    {
        _btnArray = [NSMutableArray array];
    }
    return _btnArray;
    
}

-(void)setModelArray:(NSMutableArray *)modelArray
{
    
    _modelArray = modelArray;
    
 
    
    [modelArray enumerateObjectsUsingBlock:^(HomeFocusModel* obj, NSUInteger idx, BOOL * _Nonnull stop) {
        {
            UIButton* btn = self.btnArray[idx];
            
            NSURL* url = [NSURL URLWithString:obj.img];
            
        
            [btn sd_setImageWithURL:url forState:UIControlStateNormal];
            
            [ btn setTitle:obj.name forState:UIControlStateNormal ];
            
            [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
            
            btn.titleLabel.textAlignment = NSTextAlignmentCenter;
            
            btn.titleLabel.font = [UIFont systemFontOfSize:14];
        }
    }];
    
    
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setMyUI];
    }
    return self;
    
    
}

-(void)setMyUI
{
    int count = 4;
    
    float margin = 20;
    
    float btnW = ([UIScreen mainScreen].bounds.size.width - (count+ 1)* margin)/count;
    

    
    for (int i = 0 ; i < count; i++)
    {
        HMHomeBtn* btn = [[HMHomeBtn alloc]init];
        
        [self.contentView addSubview:btn];
        
        CGFloat btnX = margin + i*(margin + btnW);
        

        
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.leading.equalTo(@(btnX));
            
            make.top.equalTo(self.contentView).offset(10);
            
            make.bottom.equalTo(self.contentView).offset(-10);
            
            make.width.equalTo(@(btnW));
            
            
        }];
        
        btn.contentMode = UIViewContentModeScaleAspectFit;

        

        
        [self.btnArray addObject:btn];
        
        
    }
    
    
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
